<template>
	<view class="template-details tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>


		<view class="" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<block v-for="(item,index) in swiperList" :key="index">
				<view class="spot" :class="cardCur==index?'active':''"></view>
			</block>
		</view>

		<view class="tn-margin">
			<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-padding-top-xs" style="margin-top: 1%;">
				<!-- <text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
				  {{ item.desc }}
				</text> -->
				<view class="justify-content-item tn-flex tn-flex-col-center">
					<tn-avatar class="" shape="circle" :src="content.avatar" size="sm">
					</tn-avatar>
					&nbsp; &nbsp; &nbsp;
					<text class="tn-color-gray">{{ content.userName }}</text>
				</view>
			<!-- 	<view class="justify-content-item tn-flex tn-flex-col-center" @click="tn('/orderPages/me')">
					<text class="tn-color-gray">主页 ></text>
				</view> -->


			</view>
			<view class="tn-margin">
			  <view class="tn-flex tn-flex-row-between">
			    <view class="justify-content-item tn-text-bold tn-text-xxl">
			     {{content.title}}
			    </view>
			  </view>
			  <view class="tn-flex tn-flex-row-between tn-margin-top">
			    <view class="justify-content-item tn-text-bold tn-color-purplered">
			      <text class="" style="font-size: 50rpx;">{{ content.price }}</text>
			      <text class="tn-text-sm">￥</text>
			    </view>
			    <view class="justify-content-item tn-color-gray tn-padding-top-xs">
			     <text class="blogger__count-icon tn-icon-footprint">&nbsp;</text>
			     <text class="tn-padding-right" style="margin-left: 5%;"> &nbsp;{{content.readNum}} </text>
			    </view>
			  </view>
			</view>
			


			<!-- 	<view class="tn-margin">
				<view class="tn-flex tn-flex-row-between">
					<view class="justify-content-item tn-text-bold tn-text-xl">
						{{content.title}}
					</view>
				</view>
			</view> -->

		
		</view>
		<view class="tn-strip-bottom"></view>
		<view class="tn-margin">
		  <view class="tn-flex tn-flex-row-between">
		    <view class="justify-content-item tn-text-bold tn-text-xl">
		      订单标签
		    </view>
		  </view>
		</view>
		<view class="">
			<view class="tn-tag-content tn-margin tn-text-justify">
				<view class="tn-flex  tn-flex-col-between" style="margin-top: 2%;">
					<view class="tn-tag-content__item tn-margin-right tn-round tn-text-sm tn-text-bold"
						:class="[`tn-bg-blue--light tn-color-blue`]">
						<text class="tn-tag-content__item--prefix" v-if="index!=0">#工时</text> {{ content.workDate }}
					</view>
					<view class="tn-tag-content__item tn-margin-right tn-round tn-text-sm tn-text-bold"
						:class="[`tn-bg-purple--light tn-color-purple`]">
						<text class="tn-tag-content__item--prefix" v-if="index!=0">#</text> {{ content.role }}
					</view>
					<view  class="tn-tag-content__item tn-margin-right tn-round tn-text-sm tn-text-bold"
						style="margin-left: 3%;"
						:class="[`tn-bg-purplered--light tn-color-purplered`]">
						<text class="tn-tag-content__item--prefix" v-if="index!=0">#</text> {{ content.endTime }}
					</view>


				</view>
			</view>
		</view>

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom"></view>

		
		<view class="tn-margin">
		  <view class="tn-flex tn-flex-row-between">
		    <view class="justify-content-item tn-text-bold tn-text-xl">
		      内容详情
		    </view>
		  </view>
		</view>

		<view class="content-backgroup tn-margin">
			<view class="resume2">
				<text>
					{{content.content}}
				</text>
			</view>
		</view>





		<!-- 悬浮按钮-->
		<view class="tn-flex tn-flex-row-between tn-footerfixed">
			<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
			  <tn-button backgroundColor="#FFF00D" padding="40rpx 0" width="90%" shadow fontBold open-type="share">
			    <text class="tn-icon-share-triangle tn-padding-right-xs tn-color-black"></text>
			    <text class="tn-color-black">分 享</text>
			  </tn-button>
			</view>
			<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
				<tn-button backgroundColor="#00FFC6" padding="40rpx 0" width="90%" shadow fontBold
					@click="successOrder()">
					<text class="tn-icon-add tn-padding-right-xs tn-color-black"></text>
					<text class="tn-color-black">确 认 接 单</text>
				</tn-button>
			</view>
		</view>
		

		<!-- 接手前上传图片 -->
		<tn-popup v-model="popup.show" :marginTop="vuex_custom_bar_height" length="50%" :mode="popup.mode"
			:backgroundColor="popup.backgroundColor" :width="popup.width" :height="popup.height"
			:borderRadius="popup.borderRadius" :closeBtn="popup.closeBtn" :closeBtnIcon="popup.closeBtnIcon"
			:closeBtnPosition="popup.closeBtnPosition" :maskCloseable="popup.maskCloseable" @close="popup.closedPopup">
			<view class="popup-content" :class="{'popup-content--center': mode === 'center'}">
				
				<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-top-xl tn-margin">
					<view class="tn-flex justify-content-item">
						<view class="tn-bg-black tn-color-white tn-text-center"
							style="border-radius: 100rpx;margin-right: 8rpx;width: 45rpx;height: 45rpx;line-height: 45rpx;">
							<text class="tn-icon-tel-circle-fill" style="font-size: 30rpx;"></text>
						</view>
						<view class="tn-text-lg tn-padding-right-xs tn-text-bold">*联系方式</view>
					</view>
					<tn-input placeholder="请填写联系方式" name="input" v-model="contactTake" inputAlign="right"></tn-input>
				
				</view>
				<!-- <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-top-xl tn-margin">
					<view class="tn-flex justify-content-item">
						<view class="tn-bg-black tn-color-white tn-text-center"
							style="border-radius: 100rpx;margin-right: 8rpx;width: 45rpx;height: 45rpx;line-height: 45rpx;">
							<text class="tn-icon-image" style="font-size: 30rpx;"></text>
						</view>
						<view class="tn-text-lg tn-padding-right-xs tn-text-bold">接单凭证(务必上传!)</view>
					</view>
					<view class="justify-content-item tn-text-df tn-color-grey" @tap="clear">
						<text class="tn-padding-xs">清空上传</text>
						<text class="tn-icon-delete"></text>
					</view>
				</view>
		
				<view class="tn-margin-left tn-padding-top-xs">
					<view class="tn-margin-left tn-padding-top-xs">
						<tn-image-upload-drag ref="imageUpload" :action="imgUpload.action" :width="236" :height="236"
							:header="imgUpload.formData" :formData="imgUpload.formData" :fileList="imgUpload.fileList"
							:disabled="imgUpload.disabled" :autoUpload="imgUpload.autoUpload"
							:maxCount="imgUpload.maxCount" :showUploadList="imgUpload.showUploadList"
							:showProgress="imgUpload.showProgress" :deleteable="imgUpload.deleteable"
							:customBtn="imgUpload.customBtn" @sort-list="onSortList" @on-success="success" />
					</view>
				</view> -->
				

				<view class="tn-flex tn-flex-row-between tn-footerfixed">
					<view class="tn-flex-2 justify-content-item tn-margin-xs tn-text-center">
						<tn-button backgroundColor="#00FFC6" padding="40rpx 0" width="90%" shadow fontBold
							@click="upload()">
							<text class="tn-icon-add tn-padding-right-xs tn-color-black"></text>
							<text class="tn-color-black">确 认 接 单</text>
						</tn-button>
					</view>
				</view>
			</view>
		</tn-popup>

		<view class='tn-tabbar-height'></view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import request from '@/common/request.js'

	export default {
		name: 'TemplateProduct',
		mixins: [template_page_mixin],
		data() {
			return {
				res: "",
				content: {},

				popup: {
					show: false,
					mode: 'bottom',
					backgroundColor: '',
					width: '',
					height: '',
					borderRadius: 0,
					closeBtn: true,
					closeBtnIcon: 'close',
					closeBtnPosition: 'top-right',
					maskCloseable: true,
				},
				imgUpload: {
					action: request.getUpload(), // action: '',
					formData: {
						apiType: 'this,ali',
						Authorization: "Bearer " + uni.getStorageSync("token"),
						image: null
					},
					fileList: [

					],
					showUploadList: true,
					customBtn: false,
					autoUpload: false,
					showProgress: false,
					deleteable: true,
					customStyle: false,
					maxCount: 9,
					disabled: false,
				},
				fileUrl: "",
				listRole:[],
				contactTake:''
			}
		},
		onLoad: function(option) {
			this.res = option.info
		},
		mounted() {
			this.loadData();
		},
		methods: {
			loadData() {
				this.content = JSON.parse(this.res);
			
			},

			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			// tab选项卡切换
			tabChange(index) {
				this.current = index
			},
			getRandomCoolBg() {
				return this.$t.colorUtils.getRandomCoolBgClass()
			},
			successOrder() { //确认接单
				this.popup.show = true;
			},
			// 手动上传文件
			upload() {
				let token = uni.getStorageSync("token") || null;
				if(token == null){
					uni.showModal({
						title: '提示：',
						content: "请先登录！",
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/minePages/regist'
								});
							}
						}
					});
				}else{
					request.get("/system/dict/data/list", {
						dictType: 'xxc_role'
					}).then((res) => {
						this.listRole = res.rows;
						this.user = uni.getStorageSync("userinfo");
						request.updateUser(this.user.userId);
						let user = uni.getStorageSync("userinfo");
						
						let dictLabel = '';
						for(let i = 0; i < this.listRole.length; i++){
							if(this.listRole[i].dictValue == user.roleApp){
								dictLabel = this.listRole[i].dictLabel
							}
						}
						if(user.roleState == 0){
							uni.showModal({
								title: '提示：',
								content: "角色未审核,请耐心等待",
								success: function(res) {
									if (res.confirm) {
										uni.reLaunch({
											url: '/pages/index'
										})
									}
								}
							});
							return;
						}
						if (this.content.role != dictLabel) {
							uni.showModal({
								title: '提示：',
								content: "您与订单角色不统一,请寻找合适的订单",
								success: function(res) {
									if (res.confirm) {
										uni.reLaunch({
											url: '/pages/index'
										})
									}
								}
							});
							return;
						}
						let img = '';
						let orderId = this.content.orderId;
						let contactTakeTemp = this.contactTake;
						uni.showModal({
							title: '提示：',
							content: "确认要接手订单吗？",
							success: function(res) {
								if (res.confirm) {
									request.post("/order/takeOrder", {
										orderId: orderId,
										takeMsg: img,
										contactTake: contactTakeTemp
									}).then((res) => {
										if (res.code == 500) {
											uni.showModal({
												title: '提示：',
												content: "同一订单不能二次接单或自己不可以接自己订单？",
												success: function(res) {
													if (res.confirm) {
														uni.reLaunch({
															url: '/orderPages/myTakeOrder'
														})
													}
												}
											});
											return;
										} else {
											uni.reLaunch({
												url: '/orderPages/myTakeOrder'
											});
										}
									});
						
								}
							}
						});
					});
				}
			},
			// 手动清空列表
			clear() {
				this.$refs.imageUpload.clear()
			},
			// 图片拖拽重新排序
			onSortList(list) {
				console.log(list);
			},
			success(data, index, array, indexNow) {
				

			},
			/* 
			 success(data, index, array, indexNow) {
			 	let user = uni.getStorageSync("userinfo");
			 
			 	let dictLabel = '';
			 	for(let i = 0; i < this.listRole.length; i++){
			 		if(this.listRole[i].dictValue == user.roleApp){
			 			dictLabel = this.listRole[i].dictLabel
			 		}
			 	}
			 	if(user.roleState == 0){
			 		uni.showModal({
			 			title: '提示：',
			 			content: "角色未审核,请耐心等待",
			 			success: function(res) {
			 				if (res.confirm) {
			 					uni.reLaunch({
			 						url: '/pages/index'
			 					})
			 				}
			 			}
			 		});
			 		return;
			 	}
			 	if (this.content.role != dictLabel) {
			 		uni.showModal({
			 			title: '提示：',
			 			content: "您与订单角色不统一,请寻找合适的订单",
			 			success: function(res) {
			 				if (res.confirm) {
			 					uni.reLaunch({
			 						url: '/pages/index'
			 					})
			 				}
			 			}
			 		});
			 		return;
			 	}
			 
			 	this.fileUrl += data.fileName + ',';
			 	if (index + 1 == array.length) {
			 		let img = this.fileUrl.substring(0, this.fileUrl.length - 1);
			 		let orderId = this.content.orderId;
			 		let contactTakeTemp = this.contactTake;
			 		uni.showModal({
			 			title: '提示：',
			 			content: "确认要接手订单吗？",
			 			success: function(res) {
			 				if (res.confirm) {
			 					request.post("/order/takeOrder", {
			 						orderId: orderId,
			 						takeMsg: img,
			 						contactTake: contactTakeTemp
			 					}).then((res) => {
			 						if (res.code == 500) {
			 							uni.showModal({
			 								title: '提示：',
			 								content: "同一订单不能二次接单或自己不可以接自己订单？",
			 								success: function(res) {
			 									if (res.confirm) {
			 										uni.reLaunch({
			 											url: '/orderPages/myTakeOrder'
			 										})
			 									}
			 								}
			 							});
			 							return;
			 						} else {
			 							uni.reLaunch({
			 								url: '/orderPages/myTakeOrder'
			 							});
			 						}
			 					});
			 
			 				}
			 			}
			 		});
			 	} else {
			 		this.$t.message.toast('请上传凭证');
			 	}
			 },
			 */
		}
	}
</script>

<style lang="scss" scoped>
	.template-product {}

	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
	}


	/* 底部悬浮按钮 start*/
	.tn-tabbar-height {
		min-height: 100rpx;
		height: calc(120rpx + env(safe-area-inset-bottom) / 2);
	}

	.tn-footerfixed {
		position: fixed;
		width: 100%;
		bottom: calc(30rpx + env(safe-area-inset-bottom));
		z-index: 1024;
		box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);

	}

	/* 底部悬浮按钮 end*/
	/* 用户头像 start */
	.logo-image {
		width: 110rpx;
		height: 110rpx;
		position: relative;
	}

	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
		border-radius: 10rpx;
		overflow: hidden;
		// background-color: #FFFFFF;
	}


	/* 间隔线 start*/
	.tn-strip-bottom-min {
		width: 100%;
		border-bottom: 1rpx solid #F8F9FB;
	}

	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/
	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 46rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://resource.tuniaokj.com/images/title_bg/title44.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 底部tabbar start*/
	.footerfixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 999;
		background-color: #FFFFFF;
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 45rpx;
			padding: 10rpx 30rpx;
			margin: 20rpx 20rpx 5rpx 0rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}

	/* 标签内容 end*/

	/* 内容图 start */
	.content-backgroup {
		z-index: -1;

		.backgroud-image {
			border-radius: 15rpx;
			width: 100%;
		}
	}

	/* 内容图 end */

	/* 商家商品 start*/
	.tn-blogger-content {
		&__wrap {
			box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
			border-radius: 20rpx;
			margin: 15rpx;
		}

		&__info {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}

		&__label {
			&__item {
				line-height: 45rpx;
				padding: 0 10rpx;
				margin: 5rpx 18rpx 0 0;

				&--prefix {
					color: #E83A30;
					padding-right: 10rpx;
				}
			}

			&__desc {
				line-height: 35rpx;
			}
		}

		&__main-image {
			border-radius: 16rpx 16rpx 0 0;

			&--1 {
				max-width: 690rpx;
				min-width: 690rpx;
				max-height: 400rpx;
				min-height: 400rpx;
			}

			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}

			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}

		&__count-icon {
			font-size: 24rpx;
			padding-right: 5rpx;
		}
	}

	.image-book {
		padding: 150rpx 0rpx;
		font-size: 16rpx;
		font-weight: 300;
		position: relative;
	}

	.image-picbook {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 15rpx 15rpx 0 0;
	}

	/* 毛玻璃*/
	.dd-glass {
		width: 100%;
		backdrop-filter: blur(20rpx);
		-webkit-backdrop-filter: blur(20rpx);
	}
</style>